package com.epam.kulibaba.components.catalog.order;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.CacheLookup;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.testng.Reporter;

import com.epam.kulibaba.components.Component;

public class LinksBarOrder extends Component {
	public static final String LINKSORDERBAR = "//div[@class = 'order']";
	public static final String LINKSORTBYPRICE = "//a[contains(@href,'sort=price')]";
	public static final String LINKSORTBYNAME = "//a[contains(@href,'sort=name')]";

	@FindBy(css = LinksBarOrder.LINKSORDERBAR)
	private WebElement linkBarOrder;

	@FindBy(xpath = LinksBarOrder.LINKSORTBYPRICE)
	@CacheLookup
	private WebElement linkSortByPrice;

	@FindBy(xpath = LinksBarOrder.LINKSORTBYNAME)
	@CacheLookup
	private WebElement linkSortByName;

	public WebElement getLinkBarOrder() {
		return linkBarOrder;
	}

	public WebElement getButtonSortByName() {
		return linkSortByName;
	}

	public WebElement getButtonSortByPrice() {
		return linkSortByPrice;
	}
	
	
	public LinksBarOrder getLinkBarOrder(WebDriver driver) {
		LinksBarOrder linkBarOrder = PageFactory.initElements(driver,
				LinksBarOrder.class);
		return linkBarOrder;
	}
	
	public static void sortProductsListByPrice(LinksBarOrder linkSortByPrice) {
		Reporter.log("Clik on link sortByPrice");
		linkSortByPrice.getButtonSortByPrice().click();
	}

	public static void sortProductsListByName(LinksBarOrder linkSortByName) {
		Reporter.log("Clik on link sortByName");
		linkSortByName.getButtonSortByName().click();
	}

}
